package toy.keli.edic.ui.home.homescreen


import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import toy.keli.edic.data.GlobalVal
import toy.keli.edic.domain.model.WordModel
import toy.keli.edic.ui.home.WordModelViewModel
import toy.keli.edic.ui.home.WordState
import toy.keli.edic.ui.home.components.ForgetButton
import toy.keli.edic.ui.home.components.KnowButton
import toy.keli.edic.ui.home.components.VagueButton
import toy.keli.edic.ui.navigation.NavScreen

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun FunctionButtons(viewModel: WordModelViewModel?=null, wordState: WordState?=null
                   , onNextWord:(Int)->Unit={}
) {

    KnowButton(modifier = Modifier
        .combinedClickable (
            onClick = {
                wordState?.wordModel?.let {
                    it.status = WordModel.STATUS_KNOW
                    viewModel?.insertHistory(it)
                    onNextWord(WordModel.STATUS_KNOW)
                }
            },
            onLongClick = {
                GlobalVal.nav.navigate("${NavScreen.routes.History}?type="+WordModel.STATUS_KNOW)
            }
        )
    ) {}

    VagueButton (modifier = Modifier.combinedClickable (
        onClick = {
            wordState?.wordModel?.let {
                it.status = WordModel.STATUS_VAGUE
                viewModel?.insertHistory(it)
                onNextWord(WordModel.STATUS_VAGUE)
            }
        },
        onLongClick = {
            GlobalVal.nav.navigate("${NavScreen.routes.History}?type="+WordModel.STATUS_VAGUE)
        }
    )){

    }

    ForgetButton(modifier = Modifier.combinedClickable (
        onClick = {
            wordState?.wordModel?.let {
                it.status = WordModel.STATUS_FORGET
                viewModel?.insertHistory(it)
                onNextWord(WordModel.STATUS_FORGET)
            }
        },
        onLongClick = {
            GlobalVal.nav.navigate("${NavScreen.routes.History}?type="+WordModel.STATUS_FORGET)
        })){}
}